package org.smartboot.flow.example;

import org.smartboot.flow.core.metrics.Metrics;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author qinluo
 * @date 2023-01-09 18:40:59
 * @since 1.0.0
 */
public class MultipleBusinessMetrics extends Metrics {

    private final Map<String, Metrics> multipleMetrics = new ConcurrentHashMap<>();

    public void addMetric(String business, String name, long value) {
        Metrics metrics = multipleMetrics.computeIfAbsent(business, (p) -> new Metrics());
        metrics.addMetric(name, value);
    }

    @Override
    public Map<String, Object> getMetrics() {
        return new HashMap<>(multipleMetrics);
    }

    @Override
    public void reset() {
        multipleMetrics.clear();
    }
}
